package com.yiqi.liebang.feature.order.view.adapter;

import android.graphics.Paint;
import android.text.TextUtils;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.suozhang.framework.framework.AM;
import com.yiqi.liebang.R;
import com.yiqi.liebang.common.widget.RatingBar;
import com.yiqi.liebang.entity.bo.TopicOrderBo;
import com.yiqi.liebang.entity.enums.TopicExpertOfflineStauts;
import com.yiqi.liebang.entity.enums.TopicExpertOnlineStauts;
import com.yiqi.liebang.entity.enums.TopicStudentOfflineStauts;
import com.yiqi.liebang.entity.enums.TopicStudentOnlineStauts;

import static com.yiqi.liebang.feature.order.view.adapter.QuestionAdapter.getDatePoor;

public class TopicAdapter extends BaseQuickAdapter<TopicOrderBo, BaseViewHolder> {
    private int mType;

    public TopicAdapter(int mType) {
        super(R.layout.item_order_topic);
        this.mType = mType;
    }

    @Override
    protected void convert(BaseViewHolder helper, TopicOrderBo item) {
        TextView textView = helper.getView(R.id.tv_user_topic_prize_yuan);
        textView.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);

        helper.setText(R.id.tv_user_topic_title, item.getTopicFormMap().getTopicName())
                .setText(R.id.tv_user_topic_num, "帮助过" + item.getTopicFormMap().getUserAccountFormMap().getHelpNum() + "人")
                .setText(R.id.tv_user_topic_time, item.getTopicFormMap().getServiceTime() + "小时/次")
                .setText(R.id.tv_user_topic_prize, item.getTopicFormMap().getTopicPrice() + "元/次")
                .setText(R.id.tv_user_topic_prize_yuan, item.getTopicFormMap().getOriginalPrice() + "元/次")
                .setText(R.id.tv_user_topic_name, item.getTopicFormMap().getUserAccountFormMap().getUserName() + "")
                .setText(R.id.tv_user_topic_position, item.getTopicFormMap().getUserAccountFormMap() == null ? "" : (TextUtils.isEmpty(item.getTopicFormMap().getUserAccountFormMap().getPosition())?"":item.getTopicFormMap().getUserAccountFormMap().getPosition()))
                .setVisible(R.id.iv_user_position, item.getTopicFormMap().getUserAccountFormMap().getIsOccupation() == 1 ? true : false)
                .setText(R.id.tv_order_topic_status, mType == 4 ? item.getTopicFormMap().getServiceType() == 0 ? TopicExpertOfflineStauts.getName(item.getOrderStates()) : TopicExpertOnlineStauts.getName(item.getOrderStates()) : item.getTopicFormMap().getServiceType() == 0 ? TopicStudentOfflineStauts.getName(item.getOrderStates()) : TopicStudentOnlineStauts.getName(item.getOrderStates()))
                .setVisible(R.id.tv_order_question_new, item.getReadStatus() == 0 ? true : false)
                .setVisible(R.id.tv_order_question_time, item.getOrderStates()==1?true:false)
                .setVisible(R.id.iv_user_certification, item.getTopicFormMap().getUserAccountFormMap() == null ? false : item.getTopicFormMap().getUserAccountFormMap().getIsBasic() == 1 ? true : false)
                .setText(R.id.tv_user_topic_type, item.getTopicFormMap().getServiceType() == 0 ? "线下约见" : "全国通话")
                .setText(R.id.tv_order_question_time, getDatePoor(item.getEndTime(), System.currentTimeMillis()))
                .setBackgroundRes(R.id.tv_user_topic_type, item.getTopicFormMap().getServiceType() == 0 ? R.drawable.list_button_xianxia : R.drawable.list_button_quanguo)
        .addOnClickListener(R.id.iv_user_topic)
        ;
        RatingBar ratingBar = helper.getView(R.id.star);
        ratingBar.setStar(item.getTopicFormMap().getStartLevel());
        AM.image().bindToCircleObject(item.getTopicFormMap().getUserAccountFormMap().getUserHead(), helper.getView(R.id.iv_user_topic));
    }
}
